import pandas as pd

# 读取Excel文件
file_path = 'd:\\Users\\Administrator\\Desktop\\git\\数据\\FhjlViewDD.xlsx'
data = pd.read_excel(file_path)

# 配置列名
date_col = '创建时间'
customer_col = '客户'
weight_col = '净重'

# 筛选6月数据
if all(col in data.columns for col in [date_col, customer_col, weight_col]):
    # 转换日期
    data[date_col] = pd.to_datetime(data[date_col])
    
    # 筛选6月数据
    june_data = data[data[date_col].dt.month == 6]
    
    # 按客户统计货运量并排序
    customer_stats = june_data.groupby(customer_col)[weight_col].sum().sort_values(ascending=False)
    
    # 创建DataFrame并保存为Excel
    result_df = pd.DataFrame({'客户': customer_stats.index, '货运量(吨)': customer_stats.values})
    result_df.to_excel('june_customer_freight_ranking.xlsx', index=False)
    
    print("表格已生成并保存为: june_customer_freight_ranking.xlsx")
    print("\n6月各客户货运需求量排名:")
    print(result_df)
else:
    print("错误：缺少必要的数据列，请检查列名配置")
    print("当前配置:", {
        '日期列': date_col,
        '客户列': customer_col,
        '重量列': weight_col
    })
    print("可用列名:", data.columns.tolist())